package com.yonyou.cyxdms.basedata.service.controller.questionnaire;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyxdms.basedata.client.domains.vo.CareQuestionVO;
import com.yonyou.cyxdms.basedata.client.domains.vo.QuestionVisitInfoVO;
import com.yonyou.cyxdms.basedata.client.domains.vo.QuestionaireVO;
import com.yonyou.cyxdms.basedata.client.dto.QuestionaireDTO;
import com.yonyou.cyxdms.basedata.service.dto.questionaire.AnswerGroupDTO;
import com.yonyou.cyxdms.basedata.service.dto.questionaire.QueryAnswerDTO;
import com.yonyou.cyxdms.basedata.service.dto.questionaire.QuestionDTO;
import com.yonyou.cyxdms.basedata.service.dto.questionaire.QuestionnaireDTO;
import com.yonyou.cyxdms.basedata.service.service.questionaire.AnswerGroupService;
import com.yonyou.cyxdms.basedata.service.service.questionaire.QuestionService;
import com.yonyou.cyxdms.basedata.service.service.questionaire.QuestionnaireService;
import com.yonyou.cyxdms.basedata.service.vo.questionaire.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 问卷相关
 *
 * @author renwd
 * @since 2019/9/19
 */
@Api(value = "问卷相关", tags = {"问卷相关"})
@RestController
@RequestMapping("/questionnaire")
public class QuestionnaireContoller {

    @Autowired
    private AnswerGroupService answerGroupService;

    @Autowired
    private QuestionService questionService;

    @Autowired
    private QuestionnaireService questionnaireService;

    /**
     * 答案信息列表
     *
     * @param current 当前页
     * @param size 一页多少条
     * @param queryAnswerDTO queryAnswerDTO
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.questionaire.AnswerGroupVO>
     * @author renwd
     * @since 2019/9/19
     */
    @GetMapping("/queryAnswerGroup")
    @ApiOperation(notes = "答案信息列表", value = "答案信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public IPage<AnswerGroupVO> queryAnswerGroupInfo(@RequestParam("pageNum") Long current, @RequestParam("limit") Long size, QueryAnswerDTO queryAnswerDTO) {
        Page<AnswerGroupVO> page = new Page<>(current, size);
        return answerGroupService.queryAnswerGroupInfo(page, queryAnswerDTO);
    }

    /**
     * 根据答案组id查询答案信息
     *
     * @param current
     * @param size
     * @param answerGroupId
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.questionaire.AnswerVO>
     * @author renwd
     * @since 2019/9/19
     */
    @GetMapping("/queryAnswerByGroupId")
    @ApiOperation(notes = "根据答案组id查询答案信息(分页)", value = "根据答案组id查询答案信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public IPage<AnswerVO> queryAnswerByGroupId(@RequestParam("pageNum") Long current, @RequestParam("limit") Long size, Long answerGroupId) {
        Page<AnswerVO> page = new Page<>(current, size);
        return answerGroupService.queryAnswerInfoById(page, answerGroupId);
    }

    /**
     * 根据答案组id查询答案信息(不分页)
     *
     * @param answerGroupId
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.questionaire.AnswerVO>
     * @author renwd
     * @since 2019/9/24
     */
    @GetMapping("/listAnswerByGroupId")
    @ApiOperation(notes = "根据答案组id查询答案信息(不分页)", value = "根据答案组id查询答案信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public List<AnswerVO> queryAnswerByGroupId(Long answerGroupId) {
        return answerGroupService.listAnswerInfoById(answerGroupId);
    }

    /**
     * 根据答案组id查询答案组信息
     *
     * @param answerGroupId
     * @return com.yonyou.cyxdms.basedata.service.vo.questionaire.AnswerGroupVO
     * @author renwd
     * @since 2019/9/19
     */
    @GetMapping("/queryAnswerGroupById")
    @ApiOperation(notes = "根据答案组id查询答案组信息", value = "根据答案组id查询答案组信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public AnswerGroupVO queryAnswerGroupById(@RequestParam("answerGroupId") Long answerGroupId) {
        return answerGroupService.queryAnswerGroupById(answerGroupId);
    }

    /**
     * 新增答案组及答案
     *
     * @param answerGroupDTO
     * @return java.lang.Integer
     * @author renwd
     * @since 2019/9/19
     */
    @ApiOperation(value = "新增答案组及答案")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping("/insertAnswerGroupInfo")
    public Integer insertAnswerInfo(@Valid @RequestBody AnswerGroupDTO answerGroupDTO) {
        return answerGroupService.insertAnswerInfo(answerGroupDTO);
    }

    /**
     * 修改答案组及答案
     *
     * @param answerGroupDTO
     * @return java.lang.Integer
     * @author renwd
     * @since 2019/9/19
     */
    @ApiOperation(value = "修改答案组及答案")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/updateAnswerGroupInfo")
    public Integer updateAnswerInfo(@Valid @RequestBody AnswerGroupDTO answerGroupDTO) {
        return answerGroupService.updateAnswerInfo(answerGroupDTO);
    }

    /**
     * 删除答案组及答案
     *
     * @param answerGroupId
     * @return java.lang.Integer
     * @author renwd
     * @since 2019/9/19
     */
    @ApiOperation(value = "删除答案组及答案")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @DeleteMapping("/deleteAnswerGroupInfo")
    public Integer deleteAnswerGroupInfo(@RequestParam("answerGroupId") Long answerGroupId) {
        return answerGroupService.deleteAnswerGroupInfo(answerGroupId);
    }

   /**
    * 问题信息列表
    *
    * @param current
    * @param size
    * @param queryAnswerDTO
    * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.questionaire.QuestionGroupVO>
    * @author dengqinag
    * @since 2019/9/20
    */
    @GetMapping("/queryQuestion")
    @ApiOperation(notes = "问题信息列表", value = "问题信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public IPage<QuestionGroupVO> queryQuestion(@RequestParam("pageNum") Long current, @RequestParam("limit") Long size, QueryAnswerDTO queryAnswerDTO) {
        Page<QuestionGroupVO> page = new Page<>(current, size);
        return questionService.queryQuestionGroupInfo(page, queryAnswerDTO);
    }


    /**
     * 新增问题信息
     *
     * @param questionDTO
     * @return java.lang.Integer
     * @author dengqiang
     * @since 2019/9/20
     */
    @ApiOperation(value = "新增问题信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping("/addQuestion")
    public Integer addQuestionInfo(@RequestBody QuestionDTO questionDTO) {
        return questionService.addQuestionInfo(questionDTO);
    }


    @GetMapping("/queryQuestionById")
    @ApiOperation(notes = "根据id查询问题信息", value = "根据id查询问题信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public QuestionVO queryQuestionById(@RequestParam("questionId") Long questionId) {
        return questionService.queryQuestionById(questionId);
    }

    /**
     * 修改问题信息
     *
     * @param questionDTO
     * @return java.lang.Integer
     * @author dengqiang
     * @since 2019/9/20
     */
    @ApiOperation(value = "修改问题信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/updateQuestion")
    public Integer updateQuestionInfo(@RequestBody QuestionDTO questionDTO) {
        return questionService.updateQuestionInfo(questionDTO);
    }

   /**
    * 删除问题信息
    *
    * @param questionId
    * @return java.lang.Integer
    * @author dengqiang
    * @since 2019/9/20
    */
    @ApiOperation(value = "删除问题信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @DeleteMapping("/deleteQuestionById")
    public Integer deleteQuestionById(@RequestParam("questionId") Long questionId) {
        return questionService.deleteQuestionById(questionId);
    }


    /**
     * 根据问题id查询问题和答案组信息
     *
     * @param current
     * @param size
     * @param questionId
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.questionaire.AnswerQuestionVO>
     * @author dengqiang
     * @since 2019/9/23
     */
    @GetMapping("/queryAnswerQuestionByQuestionId")
    @ApiOperation(notes = "根据问题id查询问题和答案组信息", value = "根据问题id查询问题和答案组信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public IPage<AnswerQuestionVO> queryAnswerQuestionByQuestionId(@RequestParam("pageNum") Long current, @RequestParam("limit") Long size, Long questionId) {
        Page<AnswerQuestionVO> page = new Page<>(current, size);
        return questionService.queryAnswerQuestionByQuestionId(page, questionId);
    }

    /**
     * 问卷信息列表
     *
     * @param current
     * @param size
     * @param queryAnswerDTO
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.questionaire.QuestionnaireInfoVO>
     * @author dengqiang
     * @since 2019/9/23
     */
    @GetMapping("/queryQuestionnaire")
    @ApiOperation(notes = "问卷信息列表", value = "问卷信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public IPage<QuestionnaireInfoVO > queryQuestionnaire(@RequestParam("pageNum") Long current, @RequestParam("limit") Long size, QueryAnswerDTO queryAnswerDTO) {
        Page<QuestionnaireInfoVO> page = new Page<>(current, size);
        return questionnaireService.queryQuestionnaire(page, queryAnswerDTO);
    }


    /**
     * 新增问卷及问卷问题内容
     *
     * @param questionnaireDTO
     * @return java.lang.Integer
     * @author dengqiang
     * @since 2019/9/23
     */
    @ApiOperation(value = "新增问卷及问卷问题内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping("/insertQuestionnaire")
    public Integer insertQuestionnaire(@RequestBody QuestionnaireDTO questionnaireDTO) {
        return questionnaireService.insertQuestionnaire(questionnaireDTO);
    }


    /**
     * 修改问卷及问卷问题内容
     *
     * @param questionnaireDTO
     * @return java.lang.Integer
     * @author dengqiang
     * @since 2019/9/22
     */
    @ApiOperation(value = "修改问卷及问卷问题内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/updateQuestionnaire")
    public Integer updateQuestionnaire(@RequestBody QuestionnaireDTO questionnaireDTO) {
        return questionnaireService.updateQuestionnaire(questionnaireDTO);
    }

    @GetMapping("/queryQuestionnaireById")
    @ApiOperation(notes = "根据id查询问卷信息", value = "根据id查询问卷信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public QuestionnaireVO queryQuestionnaireById(@RequestParam("questionnaireId") Long questionnaireId) {
        return questionnaireService.queryQuestionnaireById(questionnaireId);
    }


    /**
     * 删除问卷及问卷问题内容
     *
     * @param questionnaireId
     * @return java.lang.Integer
     * @author dengqiang
     * @since 2019/9/22
     */
    @ApiOperation(value = "删除问卷及问卷问题内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @DeleteMapping("/deleteQuestionnaireById")
    public Integer deleteQuestionnaireById(@RequestParam("questionnaireId") Long questionnaireId) {
        return questionnaireService.deleteQuestionnaireById(questionnaireId);
    }


    /**
     * 根据问卷id查询问题信息
     *
     * @param current
     * @param size
     * @param questionnaireId
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.questionaire.QuestionVisitInfoVO>
     * @author dengqiang
     * @since 2019/9/23
     */
    @GetMapping("/queryQuestionByQuestionnaireId")
    @ApiOperation(notes = "根据问卷id查询问题信息", value = "根据问卷id查询问题信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public IPage<QuestionInfoVO> queryQuestionByQuestionnaireId(@RequestParam("pageNum") Long current, @RequestParam("limit") Long size, Long questionnaireId) {
        Page<QuestionInfoVO> page = new Page<>(current, size);
        return questionnaireService.queryQuestionByQuestionnaireId(page, questionnaireId);
    }

    /**
     * 根据问卷类型查询问卷列表信息
     *
     * @param questionnaireType
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.questionaire.QuestionnaireInVO>
     * @author dengqiang
     * @since 2019/9/23
     */
    @GetMapping("/queryQuestionnaireByType")
    @ApiOperation(notes = "根据问卷类型查询问卷列表信息", value = "根据问卷类型查询问卷列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public List<QuestionnaireInVO> queryQuestionnaireByType(@RequestParam("questionnaireType") String questionnaireType) {
        return questionnaireService.queryQuestionnaireByType(questionnaireType);
    }

    /**
     * 根据id查询问卷信息
     *
     * @param questionaireId
     * @return com.yonyou.cyxdms.basedata.client.domains.vo.QuestionaireVO
     * @author renwd
     * @since 2019/9/25
     */
    @GetMapping("/getQuestionnaireById")
    @ApiOperation(notes = "根据id查询问卷信息", value = "根据id查询问卷信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public QuestionaireVO getQuestionnaireById(@RequestParam Long questionaireId) {
        return questionnaireService.getQuestionnaireById(questionaireId);
    }


    /**
     * questionnaireId查询问卷信息列表
     *
     * @param questionnaireId
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.entity.questionaire.CareQuestionVO>
     * @author dengqinag
     * @since 2019/10/11
     */
    @GetMapping("/queryQuestionByCondition")
    @ApiOperation(notes = "根据questionIdList，questionnaireId查询问卷信息列表", value = "查询问卷信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public List<CareQuestionVO> queryQuestionByCondition(QuestionaireDTO questionaireDTO) {
        return questionnaireService.queryQuestionByCondition(questionaireDTO.getQuestionIdList(), questionaireDTO.getQuestionnaireId());
    }


    /**
     * 根据answerGroupId查询答案列表
     *
     * @param answerGroupId
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.questionaire.AnswerVO>
     * @author dengqiang
     * @since 2019/10/13
     */
    @GetMapping("/queryAnswerList")
    @ApiOperation(notes = "根据answerGroupId查询答案列表", value = "根据answerGroupId查询答案列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public List<AnswerVO> queryAnswerList(@RequestParam("answerGroupId") Long answerGroupId) {
        return questionnaireService.queryAnswerList(answerGroupId);
    }

    /**
     * 根据问卷ID获取问题列表
     *
     * @author ysj
     * @date 2019/11/13
     * @param questionnaireId 问卷ID
     * @return
     */
    @GetMapping("/queryQuestionVisitInfo")
    @ApiOperation(notes = "根据问卷ID获取问题列表", value = "根据问卷ID获取问题列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "Long", paramType = "header", value = "userId"),
    })
    public List<QuestionVisitInfoVO> queryQuestionVisitInfo(@RequestParam("questionnaireId") Long questionnaireId) {
        return questionnaireService.queryQuestionVisitInfo(questionnaireId);
    }
}
